﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using COFE.Core.Filter;

namespace COFE.Data.Filter
{
    public class PaginateOptionFilterExpression :
        OptionFilterExpression<COFE.Core.Filter.PaginateOptionFilter>
    {
        public PaginateOptionFilterExpression()
            : base()
        {

        }

        public override IQueryable<Entry> ProcessQuery(
            IQueryable<Entry> input, IOptionFilter filter, IOptionFilter[] options)
        {
            var optionFilter = (COFE.Core.Filter.PaginateOptionFilter)filter;
            if (!options.Any((of) => of is SortResultOptionFilter))
                input = input.OrderBy((e) => e.Label);
            return input.Skip(optionFilter.Skip).Take(optionFilter.ItemsPerPage);
        }
    }
}
